package com.mpsc.multi.source.service.impl;


import com.mpsc.api.bean.RoleInfoEntity;
import com.mpsc.multi.source.config.datasource.DataSourceContextHolder;
import com.mpsc.multi.source.dao.RoleInfoDao;
import com.mpsc.multi.source.service.RoleInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

//@Transactional
@Service("roleInfoService")
public class RoleInfoServiceImpl implements RoleInfoService {

    @Autowired
    private RoleInfoDao roleInfoDao;

    @Override
    public void saveRoleInfo(RoleInfoEntity roleInfo) {
        roleInfoDao.saveRoleInfo(roleInfo);
       // DataSourceContextHolder.clearDB();
       // DataSourceContextHolder.setDB("datasource1");
        System.out.println();
        System.out.println(DataSourceContextHolder.getDB()+ "----------------------------------------------");
        //throw new RuntimeException("测试失误回滚！");
//        roleInfoDao.saveRoleInfo(roleInfo);
    }

    @Override
    public List<RoleInfoEntity> findSaveRoleInfo(RoleInfoEntity role) {
        roleInfoDao.saveRoleInfo(role);

        List<RoleInfoEntity>  roleList = roleInfoDao.findRoleInfoList(role.getId());
        return  roleList;
    }
}
